﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using System.Data.SqlClient;
using FisApp.utility;

namespace FisApp.Reports
{
    public partial class XtraReport3 : DevExpress.XtraReports.UI.XtraReport
    {
        int _fisId;

        public XtraReport3(int fisId)
        {
            _fisId = fisId;
            InitializeComponent();
            Init();
            //comment
        }

        private void Init()
        {
            try
            {
                string commandText = @"SELECT k.kalite_no + ' - ' + k.kalip_no AS kalite, 
                                          t.taban_marka + ' - ' + t.taban_no AS taban,
                                          d.deri_kodu + ' - ' + d.deri_aciklama AS deri,
                                          r.renk_kodu + ' - ' + r.renk_aciklama AS renk,
                                          a.astar_kodu + ' - ' + a.astar_aciklama AS astar,
                                          l.lazer_kodu + ' - ' + l.lazer_aciklama AS lazer,
                                          e.elsarac_kodu + ' - ' + e.elsarac_aciklama AS elsarac,
                                          ms.makinesarac_kodu + ' - ' + ms.makinesarac_aciklama AS makinesarac,
                                          f._39+f._40+f._41+f._42+f._43+f._44+f._45 AS toplam,
                                          replicate('0', 5 - len(f.fis_id)) + cast (f.fis_id as varchar) AS sira,
                                          f.*
                                     FROM fis f 
                                     JOIN kalite k ON k.kalite_id = f.kalite_id
                                     JOIN taban t ON t.taban_id = f.taban_id
                                     JOIN renk r ON r.renk_id = f.renk_id
                                     JOIN deri d ON d.deri_id = f.deri_id
                                LEFT JOIN astar a ON a.astar_id = f.astar_id
                                LEFT JOIN lazer l ON l.lazer_id = f.lazer_id
                                LEFT JOIN elsarac e ON e.elsarac_id = f.elsarac_id
                                LEFT JOIN makinesarac ms ON ms.makinesarac_id = f.makinesarac_id
                                    WHERE fis_id =" + _fisId;

                SqlConnection sqlConnection = null;
                sqlConnection = new SqlConnection(DBUtils.DBConnectionString);
                sqlConnection.Open();
                if (sqlConnection.State == ConnectionState.Open) // Eğer bağlantı warsa
                {
                    //Create DataAdapter
                    SqlCommand CommandToExecute = new SqlCommand(commandText, sqlConnection);
                    SqlDataAdapter daFis = new SqlDataAdapter(CommandToExecute);


                    //DataSetFis dsf = new DataSetFis();
                    dataSetFis1 = new DataSetFis();
                    //dsf.T = dt;
                    //Create a DataSet Object
                    //EmployeeDS dsEmp = new EmployeeDS();
                    //Fill the DataSet
                    daFis.Fill(dataSetFis1, dataSetFis1.Tables[0].TableName);

                    this.DataMember = dataSetFis1.fis.ToString();
                    this.DataAdapter = daFis;
                    this.DataSource = dataSetFis1;
                    this.FillDataSource();

                    if (Convert.ToInt32(dataSetFis1.Tables[0].Rows[0]["acil"]) == 1)
                    {
                        xrTable1.BackColor = Color.Red;
                    }

                    //xrPictureBox1.Image = new Bitmap(dataSetFis1.fis.);
                    //XRBinding binding2 = new XRBinding("Text", _dt, "renk_id");//("Text", DataSource, "", "Category: {0}");
                    //xrTableCell24.DataBindings.Add(binding2);
                    //xrLabel1.DataBindings.Add(binding);

                    //Let us print first row and first column of the table
                    //dsProducts.DataTableName[RowIndex].ColumnName
                    //Assign a value to the first column
                    //dsEmp.EMPLOYEE[0].empno = "12345";//This will generate compile time error.
                }
            }catch(Exception ex){
                //TODO:
            }


            //sqlConnection.Open();
            //if (sqlConnection.State == ConnectionState.Open) // Eğer bağlantı warsa
            //{
            //    using (SqlCommand CommandToExecute = new SqlCommand(commandText, sqlConnection))
            //    {
            //        using (SqlDataAdapter sda = new SqlDataAdapter(CommandToExecute))
            //        {
            //            using (DataSet ds = new DataSet())
            //            {
            //                sda.Fill(dsf);
            //                sqlConnection.Close();
            //            }
            //        }
            //    }
            //}
            //this.DataSource = _dt;


            //XRBinding binding = new XRBinding("Text", DataSource, "siparis");//("Text", DataSource, "", "Category: {0}");
            ////xrTableCell24.DataBindings.Add(binding);

            //XRBinding binding2 = new XRBinding("Text", _dt, "renk_id");//("Text", DataSource, "", "Category: {0}");
            //xrTableCell24.DataBindings.Add(binding2);
            //xrLabel1.DataBindings.Add(binding);
        }

    }
}
